//
//  DKFileBaseTask.h
//  Whistle
//
//  Created by ZhangAo on 11/10/15.
//  Copyright © 2015 BookSir. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "DKObserver.h"

typedef enum {
	DKFileTaskStatePending,
	DKFileTaskStateExecuting,
	DKFileTaskStateSuccess,
	DKFileTaskStateFailed,
	
	DKFileTaskStateDefault = DKFileTaskStatePending
} DKFileTaskState;

@class DKFileBaseTask;

@protocol DKFileTaskObserver

@optional

- (void)fileTaskStatusChanged:(DKFileBaseTask *)task;

@end

@interface DKFileBaseTask : DKObserver

- (instancetype)initWithStoreKey:(NSString *)storeKey;

@property (nonatomic, assign) DKFileTaskState state;
@property (nonatomic, strong) NSError *lastError;
@property (nonatomic, readonly, copy) NSString *storeKey;
@property (nonatomic, strong) id userInfo;

@property (nonatomic, copy) void (^successBlock)(id result);
@property (nonatomic, copy) void (^failureBlock)(NSError *error);
@property (nonatomic, copy) void (^progressBlock)(CGFloat percent, long long totalBytesExpectedToWrite);

- (void)start;

- (void)cancel;

@end
